#include "alert.h"
Alert::Alert(){
    QDateTime current = QDateTime::currentDateTime();
    QDateTime epoch = QDateTime(QDate(1970,1,1), QTime(1,1,1));
    this->alertID = QString::number(epoch.secsTo(current)).toStdString();
    this->activated = false;
    this->recurring = false;
    this->frequency = "Never";
}
Alert::Alert(int month, int day, int year, int hours, int minutes,
    string info, string name){

    QDateTime current = QDateTime::currentDateTime();
    QDateTime epoch = QDateTime(QDate(1970,1,1), QTime(1,1,1));
    this->alertID= QString::number(epoch.secsTo(current)).toStdString();
    this->alertNameID = alertID;
    this->alertNameID.append(" ");
    this->alertNameID.append(name);
    this->alertDateTime.setDate(QDate(year, month, day));
    this->alertDateTime.setTime(QTime(hours,minutes,0,0));
    this->alertInfo = info;
    this->alertName = name;
}
string Alert::getname(){
    return this->alertName;
}
string Alert::getinfo(){
    return this->alertInfo;
}
string Alert::getid(){
    return this->alertID;
}
string Alert::getnameid(){
    return this->alertNameID;
}
QString Alert::sgetdatetime(){
    return this->alertDateTime.toString("dd/MM/yyyy hh:mm:ss");
}
QDateTime Alert::getdatetime(){
    return this->alertDateTime;
}
bool Alert::getrecurring(){
    return this->recurring;
}
string Alert::getfrequency(){
    return this->frequency;
}
bool Alert::getactivated(){
    return this->activated;
}
bool Alert::getdisabled(){
    return this->disabled;
}

void Alert::setid(string id){
    this->alertID = id;
}
void Alert::setname(string name){
    this->alertName = name;
}
void Alert::setnameid(string nameid){
    this->alertNameID = nameid;
}
void Alert::setdatetime(QDateTime datetime){
    this->alertDateTime = datetime;
}
void Alert::setdatetime(string input){
    // input is type dd.mm.yyyy hh:mm:ss
    char day[3];
    int i = 0;
    day[3] = '\0';
    char month[3];
    month[3] = '\0';
    char year[5];
    year[5] = '\0';
    char hours[3];
    hours[3] = '\0';
    char minutes[3];
    minutes[3] = '\0';
    char seconds[3];
    seconds[3] = '\0';

    for(i = 0; i < 2; i++)
        day[i] = input[i];
    for(i = 0; i < 2; i++)
        month[i] = input[i + 3];
    for(i = 0; i < 4; i++)
        year[i] = input[i + 6];
    for(i = 0; i < 2; i++)
        hours[i] = input[i + 11];
    for(i = 0; i < 2; i++)
        minutes[i] = input[i + 14];

    for(i = 0; i < 2; i++)
        seconds[i] = input[i + 17];


    this->alertDateTime.setTime(QTime(atoi(hours),atoi(minutes),atoi(seconds)));
    this->alertDateTime.setDate(QDate(atoi(year), atoi(month), atoi(day)));
}
void Alert::setinfo(string info){
    this->alertInfo = info;
}
void Alert::operator=(Alert copy){
    this->alertDateTime = copy.getdatetime();
    this->alertInfo = copy.getinfo();
    this->alertName = copy.getname();
    this->alertNameID = copy.getnameid();
    this->alertID = copy.getid();
    this->frequency = copy.getfrequency();
    this->activated = copy.getactivated();
    this->recurring = copy.getrecurring();
    this->disabled = copy.getdisabled();
}
void Alert::print(){
    qDebug()<<"Date time is: " << sgetdatetime();
    qDebug()<<"Info is: " << QString::fromStdString(getinfo());
    qDebug()<<"Name is: " << QString::fromStdString(getname());
    qDebug()<<"NameID is: " << QString::fromStdString(getnameid());
    qDebug()<<"Alert ID is: " << QString::fromStdString(getid());
    qDebug()<<"Alert recurring?: " << getrecurring();
    qDebug()<<"Alert frequency: " << QString::fromStdString(getfrequency());
    qDebug()<<"Alert activated?: " << getactivated();
    qDebug()<<"Alert disabled?: " << getdisabled();

}

void Alert::setrecurring(bool input){
    this->recurring = input;
}

void Alert::setactivated(bool input){
    this->activated = input;
}
void Alert::setfrequency(string input){
    this->frequency = input;
}
void Alert::setdisabled(bool input){
    this->disabled = input;
}
